package controller;

import com.smart.domain.User;
import com.smart.infer.userInt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

@Controller
public class RegController {
    /*@Autowired
    private ChiefService chiefService;*/

    @Autowired
    private userInt mapper;

    @RequestMapping("/reg.html")
    public ModelAndView register(HttpServletRequest request)throws UnsupportedEncodingException {
        request.setCharacterEncoding("UTF-8");
        String username = request.getParameter("username");
        String address = request.getParameter("address");
        String userid=request.getParameter("userid");
        String password = request.getParameter("password");
        String phonenumber = request.getParameter("phonenumber");
        int score=20;
        User user = new User();
        user.setUsername(username);
        user.setPhonenumber(phonenumber);
        user.setAddress(address);
        user.setPassword(password);
        user.setUserid(userid);
        user.setScore(score);
        System.out.println(user);
        mapper.reg(user);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("loginAndRegister");
        return modelAndView;
    }
}
